<?php
require_once dirname(__FILE__) . '/bootstrap.php';

class ForageUnitTestCase extends PHPUnit_Framework_TestCase
{
  public function instanceOfConstraint($class)
  {
    return new PHPUnit_Framework_Constraint_IsInstanceOf($class);
  }

  public function assertInstanceOf($object, $class, $message='Object [%s] is not an instance of %s')
  {
    $constraint = $this->instanceOfConstraint($class);
    $this->assertThat($object, $constraint, sprintf($message, get_class($object), $class));
  }

  public function assertWithinMargin($number, $target, $margin)
  {
    $constraint = new PHPUnit_Framework_Constraint_LessThan($target+$margin);
    $this->assertThat($number, $constraint, sprintf('Number [%s] is more than %s greater than %s', $number, $margin, $target));

    $constraint = new PHPUnit_Framework_Constraint_GreaterThan($target-$margin);
    $this->assertThat($number, $constraint, sprintf('Number [%s] is more than %s less than %s', $number, $margin, $target));
  }
}
